package neusoft.yuejian_11.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import neusoft.yuejian_11.activity.MatchDetailActivity;
import neusoft.yuejian_11.base.BaseListAdapter;
import neusoft.yuejian_11.bean.MatchBean;
import neusoft.yuejian_11.R;
import neusoft.yuejian_11.viewHolder.MatchitemViewHolder;

import static neusoft.yuejian_11.interF.Const.BASE_URI;

/**
 * Created by neusoft on 2017/10/9.
 */

public class MatchListAdapter extends BaseListAdapter {
    public MatchListAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_match_list, parent, false);
        MatchitemViewHolder viewHolder = new MatchitemViewHolder(itemView);
        return viewHolder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, List data, int position) {
        MatchBean match = (MatchBean) data.get(position);
        MatchitemViewHolder viewHolder = (MatchitemViewHolder) holder;

        final String matchName = match.getM_name();
        final int matchId = match.getM_id();
        final String matchPhone = match.getM_phone();

        viewHolder.matchNameView.setText(matchName);

        final String matchPicture = BASE_URI+"matchpicture/"+match.getM_picture();
        Picasso.with(context)
                .load(matchPicture)
                .placeholder(R.drawable.ic_club)
                .error(R.drawable.ic_noclub)
                .into(viewHolder.imageView);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动新的Activity--俱乐部详情
                Intent intent = new Intent(context, MatchDetailActivity.class);
                intent.putExtra("m_name",matchName);
                intent.putExtra("m_id",matchId);
                intent.putExtra("m_phone",matchPhone);
                intent.putExtra("m_picture",matchPicture);
                context.startActivity(intent);
            }
        });


    }
}
